/**
 * 
 */
package com.antilia.infomaresme.pages.details;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.extensions.markup.html.tabs.PanelCachingTab;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;

import com.antilia.infomaresme.InfomaresmeApplication;
import com.antilia.infomaresme.data.dataobjects.Item;
import com.antilia.infomaresme.data.services.IImageService;
import com.antilia.infomaresme.data.services.ImageDetail;

/**
 * @author Ernesto
 *
 */
public class DetailsPanel extends Panel {

	private static final long serialVersionUID = 1L;

	/**
	 * @param id
	 * @param model
	 */
	public DetailsPanel(String id, final IModel<Item> model) {
		super(id, model);
		List<ITab> tabs = new ArrayList<ITab>();
		
		tabs.add(new PanelCachingTab(new AbstractTab(new ResourceModel("item.tabs.properties"))
		{
			private static final long serialVersionUID = 1L;

			@Override
			public Panel getPanel(String panelId)
			{
				return new PropertiesPanel(panelId, model);
			}
		}));

		final List<ImageDetail> details = getImageService().getImageDetails(model.getObject());
		
		if(details.size()>0) {
			tabs.add(new PanelCachingTab(new AbstractTab(new ResourceModel("item.tabs.images"))
			{
				private static final long serialVersionUID = 1L;
	
				@Override
				public Panel getPanel(String panelId)
				{
					return new ImageScrollPanel(panelId, details);
				}
			}));
		}
		tabs.add(new PanelCachingTab(new AbstractTab(new ResourceModel("item.tabs.location"))
		{
			private static final long serialVersionUID = 1L;

			@Override
			public Panel getPanel(String panelId)
			{
				return new LocationPanel(panelId);
			}
		}));
		
		tabs.add(new PanelCachingTab(new AbstractTab(new ResourceModel("item.tabs.news"))
		{
			private static final long serialVersionUID = 1L;

			@Override
			public Panel getPanel(String panelId)
			{
				return new NewsPanel(panelId, model);
			}
		}));
		
		
		add(new AjaxTabbedPanel("tabs", tabs));
	}

	public IImageService getImageService() {
		return InfomaresmeApplication.getQAApplication().getImageService();
	}

}
